//粉丝
class Fan{
    constructor(name){
        this.name = name
    }

    update(){
        console.log(`${this.name}更新状态`)
    }
}

//三个粉丝
let f1 = new Fan('zs');

let f2 = new Fan('lisi');

let f3 = new Fan('tom');

class Star{
    constructor(){
        this.fans = []; //放置所有的粉丝
    }

    add(fan){
        this.fans.push(fan);
    }

    notify(){
        //通知所有的粉丝更新状态
        this.fans.forEach(fan => fan.update())
    }
}

let star = new Star()

star.add(f1);

star.add(f2);

star.add(f3);

let public = document.querySelector('#public');

public.addEventListener('click',() => {
    star.notify();
})


